﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Users_NetMuList : BasePage
{
    private NetMuBLL bll = new NetMuBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/NetMuList.aspx", "请您登录", true);
        if(!IsPostBack)
        {
            getMyCreateNetMus();
        }
    }

    protected string getNetMuTypeName(string NetMuTypeId)
    {
        string str = ((NetMuTypeEnum)StringHelper.isNumber_int(NetMuTypeId)).ToString();
        return str;
    }

    private void getMyCreateNetMus()
    {
        Users_Model userModel = Base_GetUserInfo;
        string propertyItems = " id,MuId,MuName,MuType,CreateDate ";
        DataTable dataTable = bll.getMyCreateMetMus(userModel.UserId, propertyItems);
        rptNetMus.DataSource = dataTable;
        rptNetMus.DataBind();
    }

    private bool deleteNetMu(int id)
    {
        int count = 0;
        count = bll.DeleteNetMu(id);
        return count > 0 ? true : false;
    }

    protected void rptNetMus_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        bool bo = false;
        //Response.Write("<script>alert('"+btnDelete.CommandArgument+"');</script>");
        if (e.CommandName == "delete")
        {
            LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
            if (btnDelete != null)
            {
                string id = btnDelete.CommandArgument;
                try
                {
                    bo = deleteNetMu(StringHelper.isNumber_int(id));
                }
                catch
                {
                    bo = false;
                }
            }
        }
        if (e.CommandName == "CreateHtml")
        {

            NetMu_Model HTMLmd = NetMu_Bll.CreatNew.getNetMuDetailInfo(StringHelper.isNumber_int(e.CommandArgument.ToString()));
            string NumUrl = HTMLmd.MuId + ".html";

            string CreateHtmlUrl = configInfo.InstallDir + "Html/" + Channel_Type.gravestone + "/" + NumUrl;
            TempleBll.CreateNew.TempleCreate(Server.MapPath(CreateHtmlUrl), NumUrl, Channel_Type.gravestone, true);
            Response.Write("<script>alert('生成成功！');location.href='NetMuList.aspx';</script>");
            Response.End();
        }
        if (e.CommandName == "manage")
        {
            LinkButton btnManage = e.Item.FindControl("btnManage") as LinkButton;
            if (btnManage != null)
            {
                string id = btnManage.CommandArgument;
                try
                {
                    Response.Redirect("NetMuManage_" + id + ".aspx");
                }
                catch
                {
                }
            }
        }
        getMyCreateNetMus();
    }

    
}
